/*
 * communication.h
 *
 *  Created on: 08.03.2011
 *      Author: nick
 */

#ifndef COMMUNICATION_H_
#define COMMUNICATION_H_

#include <p33Fxxxx.h>
#include <uart.h>
#include <stdlib.h>
#include "sensor_typedefs.h"
#include "hardware_settings.h"

//UART-Settings
#define BAUDRATE 38400
#define KORREKTUR_BAUD 1
#define BRGVAL ((FCY/BAUDRATE)/16)-1 + KORREKTUR_BAUD

// Clock-Specific settings
#ifdef FCY_40
#define IDLE_LINE_TIMEOUT 11200       //FCY = 40MHz
#define SERVOTIMER_LOWER_LIMIT 627       //FCY = 40MHz
#define SERVOTIMER_UPPER_LIMIT 1275       //FCY = 40MHz
#elif FCY_37
#define SERVOTIMER_LOWER_LIMIT 580       //FCY = 37MHz
#define SERVOTIMER_UPPER_LIMIT 1180       //FCY = 37MHz
#define IDLE_LINE_TIMEOUT 10360       //FCY = 37MHz
#endif


#define SERVOTIMER_DIFF (SERVOTIMER_UPPER_LIMIT - SERVOTIMER_LOWER_LIMIT)/100

//! init UART1 - TX disabled
void initUart(void);
//! init Timer2 - used for idle line timeout detection
void initTimer(void);

void initChangeNotification(void);

//! send Sensor Data valueMax/Min = [16384, -16383] if the val is bigger/smaller it gets cut off
void sendSensorData( ESensorAdr, ESensorValClass, int value, int alarm );
//! send a char array over UART
void sendArray( char *array, int size );

#endif /* COMMUNICATION_H_ */
